package com.yao2san.simdif.controller;

import com.github.pagehelper.PageInfo;
import com.yao2san.common.response.ResponseData;
import com.yao2san.simdif.bean.request.*;
import com.yao2san.simdif.bean.response.DatasourceListRes;
import com.yao2san.simdif.service.DatasourceManageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author wxg
 */
@RestController
@RequestMapping("datasourceManage")
public class DatasourceManageController {
    @Autowired
    private DatasourceManageService datasourceManageService;

    @PostMapping("add")
    public ResponseData<Long> add(@RequestBody DatasourceAddReq req) {
        return ResponseData.success(datasourceManageService.add(req));
    }
    @GetMapping("list")
    public ResponseData<PageInfo<DatasourceListRes>> list(DatasourceListReq req) {
        return ResponseData.success(datasourceManageService.list(req));
    }
    @PostMapping("update")
    public ResponseData<Long> sync(@RequestBody DatasourceUpdateReq req) {
        datasourceManageService.update(req);
        return ResponseData.success();
    }
    @PostMapping("delete")
    public ResponseData<Long> delete(@RequestBody DatasourceDeleteReq req) {
        datasourceManageService.delete(req);
        return ResponseData.success();
    }
    @PostMapping("sync")
    public ResponseData<Long> sync(@RequestBody DatasourceSyncReq req) {
        datasourceManageService.sync(req);
        return ResponseData.success();
    }

    @PostMapping("testConnection")
    public ResponseData<Long> testConnection(@RequestBody DatasourceConnectionTestReq req) {
        datasourceManageService.testConnection(req);
        return ResponseData.success();
    }

}
